home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12419 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  69 lines

  1. Path: ix.netcom.com!news
  2. From: Robert Kleemann <goose@ix.netcom.con>
  3. Newsgroups: comp.lang.c++
  4. Subject: STL and namespaces?
  5. Date: Tue, 19 Mar 1996 12:34:20 -0800
  6. Organization: Netcom
  7. Message-ID: <314F1A4C.2868@ix.netcom.con>
  8. NNTP-Posting-Host: sea-wa4-21.ix.netcom.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-NETCOM-Date: Tue Mar 19  2:33:52 PM CST 1996
  13. X-Mailer: Mozilla 2.0 (Win95; I)
  14.  
  15. I've been using The HP STL (Dec95 version) with the Microsoft VC4 
  16. Compiler for the past few months and have taken Microsoft's 
  17. recommendation to stick all the STL include files in its own namespace 
  18. to avoid global operator conflicts with Microsoft's class library (MFC). 
  19.  The name std is recommend by ANSI for the standard template library 
  20. namespace.
  21.  
  22. After tweaking some of the STL files this has worked pretty well except 
  23. for the following problems:
  24.  
  25. 1) global operators cannot be accessed without the namespace prefix eg:
  26. std::string s1;
  27. std::string s2;
  28. if (s1==s2) // this doesn't work
  29.     ;
  30. if (std::operator==(s1,s2)) // this does work
  31.     ;
  32.  
  33. 2) STL algorithms that use global operators don't work on classes that 
  34. define these operators eg:
  35.  
  36. class C
  37. {
  38.     C();
  39.     C(const C& c);
  40.     C& operator=(const C& c);
  41.     friend bool operator==(const C& c1, const C& c2);
  42. };
  43. inline bool operator==(const C& c1, const C& c2)
  44. {
  45.     return true;
  46. }
  47. void main()
  48. {
  49.     std::list<C> container;
  50.     std::list<C>::iterator i;
  51.     // the following line will not compile because 
  52.     // find require operator== to be defined for C
  53.     i = std::find( container.begin(), container.end(), 
  54.         C() );
  55. }
  56.  
  57. The first problem is expected and and although it makes the code less 
  58. readable, it is not a major problem.  The second problem has no clear 
  59. workaround and makes me want to stop using namespaces.
  60.  
  61. My question is: are other people out there using STL with namespaces?  
  62. Have you run into these problems?  Have you found better workarounds?  
  63. Can I expect these namespace problems to be fixed in future STL 
  64. implementations or would I be better off including STL in global space 
  65. and instead try sticking MFC in a namespace.
  66.  
  67. thanx!
  68. Robert
  69.